import React, {PureComponent} from 'react';
import BaseComponent from '../base/BaseComponent';
import {connect} from 'react-redux';
import {View, Keyboard} from 'react-native';
import {updateUserInfo} from '../../redux/action';
import WebView from 'react-native-webview';
import PropTypes from 'prop-types';
import {LinearButton, ImageButton} from '../../components/Button';
import I18n from 'react-native-i18n';
import {NormalHeader} from '../../components/NavigationHeader';
import {updateUser} from '../../api/user';
import {BASE_API} from '../../config';

class ServiceScreen extends BaseComponent {
  constructor(props) {
    super(props);

    this.state = {
      content: '',
    };
  }

  agreePress = () => {
    // updateUser({
    //   agreeService: 1,
    //   userToken: this.props.userInfo.token,
    // })
    //   .then(async (res) => {
    //     await this.props.updateUserInfo(res.data);
    this.props.navigation.state.params.agree();
    this.props.navigation.goBack();
    // })
    // .catch((err) => {
    //   this._showAlert(err.msg || err);
    // });
  };

  renderComponent = () => {
    return (
      <View style={{flex: 1, backgroundColor: '#160231'}}>
        <NormalHeader
          navigation={this.props.navigation}
          text="Service"
          left={{
            icon: require('../../assets/common/common_back_white.png'),
            onPress: () => {
              Keyboard.dismiss();
              this.props.navigation.goBack();
            },
          }}
        />
        <WebView source={{uri: BASE_API + '/service.html'}} />
        <View style={{padding: 20}}>
          <LinearButton
            text="I Agree"
            buttonStyle={{backgroundColor: '#FFCB26'}}
            onPress={this.agreePress}
          />
        </View>
      </View>
    );
  };
}

const mapStateToProps = (state) => ({
  userInfo: state.User.userInfo,
});

const mapDispatchToProps = (dispatch) => ({
  updateUserInfo: (item) => dispatch(updateUserInfo(item)),
});

export default connect(mapStateToProps, mapDispatchToProps)(ServiceScreen);
